import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import tailwindcss from 'tailwindcss'
import uniTailwind from '@uni-helper/vite-plugin-uni-tailwind'
// https://vitejs.dev/config/
export default defineConfig({
  css: {
    postcss: {
      plugins: [
        tailwindcss({
          content: ['./src/**/*.{html,js,ts,jsx,tsx,vue}'],
          presets: [
            require('tailwindcss-rem2px-preset').createPreset({
              // 32 意味着 1rem = 32rpx
              fontSize: 32,
              // 转化的单位,可以变成 px / rpx
              unit: 'rpx',
            }),
          ],
        }),
      ],
    },
  },
  build: {
    // 开发阶段启用源码映射：https://uniapp.dcloud.net.cn/tutorial/migration-to-vue3.html#需主动开启-sourcemap
    sourcemap: process.env.NODE_ENV === 'development',
  },
  plugins: [uni(), uniTailwind()],
  server: {
    host: 'localhost', // 指定服务器应该监听哪个IP地址,默认：localhost
    port: 5173, // 指定开发服务器端口,默认：5173
    proxy: {
      // 为开发服务器配置自定义代理规则
      // 带选项写法：http://localhost:5173/api/posts -> http://jsonplaceholder.typicode.com/posts
      '/h5image': {
        target: 'https://image.queqiao77.top', // 目标接口
        changeOrigin: true, // 是否换源
        rewrite: (path) => path.replace(/^\/h5image/, ''),
      },
    },
  },
})
